package com.astar.service.impl;

import com.astar.entity.CustomQuestion;
import com.astar.entity.CustomUser;
import com.astar.entity.PraCouChapQuestion;
import com.astar.entity.PractiseCourseChapter;
import com.astar.mapper.PraCouChapQuestionMapper;
import com.astar.service.IPraCouChapQuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 分类练习-科目-章节-题目  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-01-31
 */
@Service
public class PraCouChapQuestionServiceImpl extends ServiceImpl<PraCouChapQuestionMapper, PraCouChapQuestion> implements IPraCouChapQuestionService {


    @Autowired
    HttpServletRequest request;
    @Autowired
    private PraCouChapQuestionMapper praCouChapQuestionMapper;



    @Override
    public List<CustomQuestion> selectAll(CustomQuestion customQuestion) {
        return praCouChapQuestionMapper.selectAll(customQuestion);
    }



    @Override
    public List<CustomQuestion> selectQuestionType() {
        return praCouChapQuestionMapper.selectQuestionType();
    }

    @Override
    public List<PractiseCourseChapter> selectChapter() {
        return praCouChapQuestionMapper.selectChapter();
    }

    @Override
    public List<CustomQuestion> changeChapter(Integer id) {
        return praCouChapQuestionMapper.changeChapter(id);
    }

    @Override
    public int insert(PraCouChapQuestion praCouChapQuestion) {
        HttpSession session= request.getSession();
        List<CustomUser> user = (List<CustomUser>) session.getAttribute("menus");
        praCouChapQuestion.setCreatedBy(user.get(0).getLoginName());
        LocalDateTime localDateTime3 = LocalDateTime.now();
        praCouChapQuestion.setCreatedTime(localDateTime3);
        return praCouChapQuestionMapper.insert(praCouChapQuestion);
    }

    @Override
    public int deleteForIds(PraCouChapQuestion praCouChapQuestion) {
        praCouChapQuestion.setStatus("N");
        return praCouChapQuestionMapper.updateById(praCouChapQuestion);
    }

    @Override
    public CustomQuestion view(Integer id) {
        return praCouChapQuestionMapper.selectOnes(id);
    }

    @Override
    public int updateForId(PraCouChapQuestion praCouChapQuestion) {
        return praCouChapQuestionMapper.updateById(praCouChapQuestion);
    }
}
